package servlet;

import dao.UserDao;
import pojo.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/enrollServlet")
public class EnrollServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String nick = req.getParameter("nick");
        String email = req.getParameter("email");
        String password = req.getParameter("password");
        String sex = req.getParameter("sex");
        String sign = req.getParameter("sign");

        String id = email.replace("@qq.com", "");
        User user = new User(id, password, nick, null, email, null, sex, null, sign, 0, 0);
        UserDao userDao = new UserDao();
        userDao.addNewUser(user);
        PrintWriter writer = resp.getWriter();
        writer.write("ok");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("enroll post...");
        this.doGet(req, resp);
    }
}
